<template>
  <div class="eventLevel">
    <CommonBtn label-name="行政城市管理" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+(item.type=='search'?item.proxy:item.value)}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions" @dbClick="openItem"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event=='detail()')"
                :outBtn="button" :props="add"
                :original-data="row" :add-url="$api.API_ADMIN_CITY_ADD" :edit-url="$api.API_ADMIN_CITY_UPDATE"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_ADMIN_CITY_EXPORT" :conditions="conditions"></CommonExport>

    <EnsurePopUp :out-btn="button" @close="close" @refresh="conditionChange" :original-data="row"
                 :delete-url="$api.API_ADMIN_CITY_SET"></EnsurePopUp>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList"
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import EnsurePopUp from "../../common/EnsurePopUp";
    export default {
        name:'adminCityList',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.DELETE,
                    this.$config.BTNS.FORBIDEN,
                    this.$config.BTNS.ENABLE,
                    this.$config.BTNS.DETAIL,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'provinceName',
                        label:'省份',
                        search:true,
                        type:'text'
                    },
                    {
                        prop: 'cityName',
                        label: '行政城市',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'adminCityCode',
                        label:'区县代码',
                        search:true,
                        type:'text'
                    },
                    {
                        prop: 'adminCity',
                        label: '区县',
                        search:true,
                        type:'text'
                    },
                    {
                        prop: 'fKCityName',
                        label: '关联城市',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'cityName',
                                label:'城市名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop: 'cityCode',
                                label: '城市代码',
                                search:true,
                                type:'text'
                            },
                            {
                                prop: 'isValid',
                                label: '是否有效'
                            },
                            {
                                prop:'provinceName',
                                label:'所属省份',
                                search:true,
                                type:'search',
                                columns:[
                                    {
                                        prop: 'provinceName',
                                        label: '省份名称',
                                        search:true,
                                        type:'text'
                                    },
                                    {
                                        prop:'provinceCode',
                                        label:'省份代码',
                                        search:true,
                                        type:'text'
                                    },
                                    {
                                        prop: 'isValid',
                                        label: '是否有效'
                                    }
                                ],
                                searchUrl:this.$api.API_QUERYPROVINCE,
                                searchLabel:'省份信息',
                                searchProxy:'provinceName',
                                queryProp:'fkProvince',
                                searchValue:'pkid'
                            }
                        ],
                        searchUrl:this.$api.API_QUERYCITY,
                        searchLabel:'城市信息',
                        searchProxy:'cityName',
                        searchValue:'pkid',
                        proxy:'fKCityName',
                        queryProp:'fkCity',
                    },
                    {
                        prop:'isValid',
                        label:'是否有效',
                        customSet(value) {
                            if (value == 1) {
                                return 'true'
                            }
                            return 'false'
                        },
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl: this.$api.API_ADMIN_CITY_QUERY,
                button:null,
                add:{
                    label:'行政城市',
                    addItems:[
                        {name:'省份',prop:'provinceName',type:'text',required:true},
                        {name:'行政城市',prop:'cityName',type:'text',required:true},
                        {name:'区县代码',prop:'adminCityCode',type:'text',required:true,disable:true,placeholder:'系统自动生成'},
                        {name:'区县',prop:'adminCity',type:'text',required:true},
                        {name:'关联城市',prop:'fkCity',proxy:'fKCityName',type:'search',
                            type:'search',
                            columns:[
                                {
                                    prop:'cityName',
                                    label:'城市名称',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop: 'cityCode',
                                    label: '城市代码',
                                    search:true,
                                    type:'text'
                                },
                               {
                                    prop: 'isValid',
                                    label: '是否有效'
                                },
                                {
                                    prop:'provinceName',
                                    label:'所属省份',
                                    search:true,
                                    type:'search',
                                    columns:[
                                        {
                                            prop: 'provinceName',
                                            label: '省份名称',
                                            search:true,
                                            type:'text'
                                        },
                                        {
                                            prop:'provinceCode',
                                            label:'省份代码',
                                            search:true,
                                            type:'text'
                                        },
                                        {
                                            prop: 'isValid',
                                            label: '是否有效'
                                        }
                                    ],
                                    searchUrl:this.$api.API_QUERYPROVINCE,
                                    searchLabel:'省份信息',
                                    searchProxy:'provinceName',
                                    queryProp:'fkProvince',
                                    searchValue:'pkid'
                                }
                            ],
                            searchUrl:this.$api.API_QUERYCITY,
                            searchLabel:'城市信息',
                            searchProxy:'cityName',
                            searchValue:'pkid'
                        },
                        {name:'排序',prop:'sortCode',type:'text',required:true,disable:true,placeholder: '系统自动生成'},
                        {name:'备注',prop:'memo',type:'textarea',placeholder:'最多100个中文'},
                    ],
                },
                conditions:[],
                row:{}
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()' || item.event == 'Delete()' || item.event == 'disable()' || item.event == 'enable()' || item.event == 'detail()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
            },
            conditionChange(conditions) {
                this.row = null
                this.$refs.list.search()
            },
            openItem(item) {
                this.button = this.$config.BTNS.DETAIL
            },
            close(item) {
                this.button = item
            }
        },
        components:{CommonExport, SearchPopUp, CommonList,CommonBtn,CommonEdit,EnsurePopUp},
    }
</script>
